
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Task 4: Modification · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-flexible-alerts/style.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-auto-scroll-table/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../../gitbook/gitbook-plugin-theme-comscore/test.css">
                
            
        

    

    
        
        <link rel="stylesheet" href="../../styles/website.css">
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../ch02/lab-2.html" />
    
    
    <link rel="prev" href="nju-gitlab.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../../">
            
                <a href="../../">
            
                    
                    Computer Network Lab Manual
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="lab-1.html">
            
                <a href="lab-1.html">
            
                    
                    Lab 1: Switchyard & Mininet
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="prerequisites.html">
            
                <a href="prerequisites.html">
            
                    
                    Task 1: Prerequisites
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1.1" data-path="linux.html">
            
                <a href="linux.html">
            
                    
                    Linux
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.2" data-path="python.html">
            
                <a href="python.html">
            
                    
                    Python
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.1.3" data-path="git.html">
            
                <a href="git.html">
            
                    
                    Git
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="workflow.html">
            
                <a href="workflow.html">
            
                    
                    Task 2: Workflow
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.2.1" data-path="vscode.html">
            
                <a href="vscode.html">
            
                    
                    VS Code
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.2" data-path="mininet.html">
            
                <a href="mininet.html">
            
                    
                    Mininet
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.3" data-path="wireshark.html">
            
                <a href="wireshark.html">
            
                    
                    Wireshark
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2.4" data-path="switchyard.html">
            
                <a href="switchyard.html">
            
                    
                    Switchyard
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="nju-gitlab.html">
            
                <a href="nju-gitlab.html">
            
                    
                    Task 3: NJU GitLab
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2.4" data-path="modification.html">
            
                <a href="modification.html">
            
                    
                    Task 4: Modification
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../ch02/lab-2.html">
            
                <a href="../ch02/lab-2.html">
            
                    
                    Lab 2: Learning Switch
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../ch02/preparation.html">
            
                <a href="../ch02/preparation.html">
            
                    
                    Task 1: Preparation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../ch02/basic-switch.html">
            
                <a href="../ch02/basic-switch.html">
            
                    
                    Task 2: Basic Switch
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../ch02/timeouts.html">
            
                <a href="../ch02/timeouts.html">
            
                    
                    Task 3: Timeouts
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="../ch02/lru.html">
            
                <a href="../ch02/lru.html">
            
                    
                    Task 4: Least Recently Used
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="../ch02/ltv.html">
            
                <a href="../ch02/ltv.html">
            
                    
                    Task 5: Least Traffic Volume
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="../ch02/faq.html">
            
                <a href="../ch02/faq.html">
            
                    
                    FAQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../ch03/ipv4-router.html">
            
                <a href="../ch03/ipv4-router.html">
            
                    
                    Lab 3-5: IPv4 Router
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../ch03/subch01/lab-3.html">
            
                <a href="../ch03/subch01/lab-3.html">
            
                    
                    Lab 3: Respond to ARP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1.1" data-path="../ch03/subch01/preparation.html">
            
                <a href="../ch03/subch01/preparation.html">
            
                    
                    Task 1: Preparation
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.2" data-path="../ch03/subch01/handle-arp-request.html">
            
                <a href="../ch03/subch01/handle-arp-request.html">
            
                    
                    Task 2: Handle ARP Request
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.1.3" data-path="../ch03/subch01/arp-table.html">
            
                <a href="../ch03/subch01/arp-table.html">
            
                    
                    Task 3: Cached ARP Table
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../ch03/faq.html">
            
                <a href="../ch03/faq.html">
            
                    
                    FAQ
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../../appendix/appendix.html">
            
                <a href="../../appendix/appendix.html">
            
                    
                    Appendix
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../../appendix/environment-setup.html">
            
                <a href="../../appendix/environment-setup.html">
            
                    
                    Environment Setup
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../../appendix/about-this-repository.html">
            
                <a href="../../appendix/about-this-repository.html">
            
                    
                    About This Repository
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href="../.." >Task 4: Modification</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="task-3-modification"><a name="task-3-modification" class="plugin-anchor" href="#task-3-modification"><i class="fa fa-link" aria-hidden="true"></i></a>Task 3: Modification</h1>
<h2 id="preparation"><a name="preparation" class="plugin-anchor" href="#preparation"><i class="fa fa-link" aria-hidden="true"></i></a>Preparation</h2>
<p>Let&apos;s start with our example files.</p>
<p>Create a directory named <code>lab_1</code> in <code>~/switchyard</code>. Your should start by copying the template files <code>examples/start_mininet.py</code>, <code>examples/myhub.py</code> and <code>examples/hubtests.py</code> into <code>lab_1</code>. And your project will look like</p>
<pre><code>switchyard/
  &#x251C;&#x2500;docs/
  &#x251C;&#x2500;.../
+ &#x251C;&#x2500;lab_1/
+ &#x2502; &#x251C;&#x2500;hubtests.py
+ &#x2502; &#x251C;&#x2500;myhub.py
+ &#x2502; &#x2514;&#x2500;start_mininet.py
  &#x251C;&#x2500;.gitignore
  &#x2514;&#x2500;...
</code></pre><h2 id="play-the-tutorial-again"><a name="play-the-tutorial-again" class="plugin-anchor" href="#play-the-tutorial-again"><i class="fa fa-link" aria-hidden="true"></i></a>Play the Tutorial Again</h2>
<p>You have done the tutorial. However it is necessary to work by yourself. So modify our examples files.</p>
<blockquote>
<p>[!TIP]
We suggest that you can commit in Git when you complete one step.</p>
</blockquote>
<div></div>

<blockquote>
<p>[!WARNING]
All of your modifications should be done on the files under your directory <code>lab_1</code>. We will check and compare the <strong>git commits</strong> to judge the originality of your work. So remember to commit every time you complete one small task.</p>
</blockquote>
<h3 id="step-1-modify-the-mininet-topology"><a name="step-1-modify-the-mininet-topology" class="plugin-anchor" href="#step-1-modify-the-mininet-topology"><i class="fa fa-link" aria-hidden="true"></i></a>Step 1: Modify the Mininet topology</h3>
<p>In the section <a href="mininet.html">Mininet</a>, we introduced how to construct a topology. So here we have two options for you, choose <strong>one</strong> to implement. &#x2705; Then show the details of how you build the topology in your report.</p>
<ul>
<li>Delete <code>server2</code> in the topology,</li>
<li>Or create a different topology containing 6 nodes using hosts and hubs (don&apos;t use other kinds of devices).</li>
</ul>
<p>The file you need to modify is <code>lab_1/start_mininet.py</code>.</p>
<h3 id="step-2-modify-the-logic-of-a-device"><a name="step-2-modify-the-logic-of-a-device" class="plugin-anchor" href="#step-2-modify-the-logic-of-a-device"><i class="fa fa-link" aria-hidden="true"></i></a>Step 2: Modify the logic of a device</h3>
<p>In the section <a href="switchyard.html">Switchyard</a>, we introduced how to program a device. Your task is to count how many packets pass through a hub in and out. You need to log the statistical result every time you receive one packet with the format of each line <code>in:&lt;ingress packet count&gt; out:&lt;egress packet count&gt;</code>. For example, if there is a packet that is not addressed to the hub itself, then the hub may log <code>in:1 out:2</code>. &#x2705; Then show the log of your hub when running it in Mininet and how you implement it in your report.</p>
<blockquote>
<p>[!NOTE]
In the old version we need you to print the timestamp then we remove it. So many students ask why because there is a function <code>log_info</code> which prints the time of log output. However we want you to log the packet arrival time which is different from output time.</p>
<p>Because our explanation is late, if you have implemented it in another way, you do <strong>not</strong> need to change.</p>
</blockquote>
<p>The file you need to modify is <code>lab_1/myhub.py</code>.</p>
<h3 id="step-3-modify-the-test-scenario-of-a-device"><a name="step-3-modify-the-test-scenario-of-a-device" class="plugin-anchor" href="#step-3-modify-the-test-scenario-of-a-device"><i class="fa fa-link" aria-hidden="true"></i></a>Step 3: Modify the test scenario of a device</h3>
<p>In the section <a href="switchyard.html">Switchyard</a>, we introduced how to write the test case. So here we have two options for you, choose <strong>one</strong> to implement. &#x2705; Then show the details of your test cases in your report.</p>
<ul>
<li>Create one test case by using the given function <code>mk_pkt</code> with different arguments,</li>
<li>Or create one test case with your handmade packet.</li>
</ul>
<p>The file you need to modify is <code>lab_1/hubtests.py</code>.</p>
<h3 id="step-4-run-your-device-in-mininet"><a name="step-4-run-your-device-in-mininet" class="plugin-anchor" href="#step-4-run-your-device-in-mininet"><i class="fa fa-link" aria-hidden="true"></i></a>Step 4: Run your device in Mininet</h3>
<p>In the section <a href="switchyard.html">Switchyard</a>, we introduced how to run Switchyard programs in Mininet. So run your new hub in your new topology and make sure it works. &#x2705; Show the procedure in your report.</p>
<h3 id="step-5-capture-using-wireshark"><a name="step-5-capture-using-wireshark" class="plugin-anchor" href="#step-5-capture-using-wireshark"><i class="fa fa-link" aria-hidden="true"></i></a>Step 5: Capture using Wireshark</h3>
<p>Both in section <a href="wireshark.html">Wireshark</a> and <a href="switchyard.html">Switchyard</a>, we introduced how to capture packets. In your own topology, capture packets on one host (no hub) while creating some traffic. <strong>Save your capture file</strong> and submit it with your report and code. &#x2705; Also you need to describe the details of your capture file.</p>

<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="nju-gitlab.html" class="navigation navigation-prev " aria-label="Previous page: Task 3: NJU GitLab">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../ch02/lab-2.html" class="navigation navigation-next " aria-label="Next page: Lab 2: Learning Switch">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Task 4: Modification","level":"1.2.4","depth":2,"next":{"title":"Lab 2: Learning Switch","level":"1.3","depth":1,"path":"content/ch02/lab-2.md","ref":"content/ch02/lab-2.md","articles":[{"title":"Task 1: Preparation","level":"1.3.1","depth":2,"path":"content/ch02/preparation.md","ref":"content/ch02/preparation.md","articles":[]},{"title":"Task 2: Basic Switch","level":"1.3.2","depth":2,"path":"content/ch02/basic-switch.md","ref":"content/ch02/basic-switch.md","articles":[]},{"title":"Task 3: Timeouts","level":"1.3.3","depth":2,"path":"content/ch02/timeouts.md","ref":"content/ch02/timeouts.md","articles":[]},{"title":"Task 4: Least Recently Used","level":"1.3.4","depth":2,"path":"content/ch02/lru.md","ref":"content/ch02/lru.md","articles":[]},{"title":"Task 5: Least Traffic Volume","level":"1.3.5","depth":2,"path":"content/ch02/ltv.md","ref":"content/ch02/ltv.md","articles":[]},{"title":"FAQ","level":"1.3.6","depth":2,"path":"content/ch02/faq.md","ref":"content/ch02/faq.md","articles":[]}]},"previous":{"title":"Task 3: NJU GitLab","level":"1.2.3","depth":2,"path":"content/ch01/nju-gitlab.md","ref":"content/ch01/nju-gitlab.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["theme-comscore","back-to-top-button","-lunr","-search","search-pro","github","splitter","flexible-alerts","page-toc-button","auto-scroll-table","popup","anchors"],"pluginsConfig":{"styles":{"website":"styles/website.css"},"github":{"url":"https://github.com/shellqiqi/nju-network-experiments"},"splitter":{},"search-pro":{},"auto-scroll-table":{},"popup":{},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"theme-comscore":{},"page-toc-button":{},"back-to-top-button":{},"flexible-alerts":{"danger":{"className":"danger","icon":"fa fa-ban","label":"Attention"},"note":{"className":"info","icon":"fa fa-info-circle","label":"Note"},"style":"callout","tip":{"className":"tip","icon":"fa fa-lightbulb-o","label":"Tip"},"warning":{"className":"warning","icon":"fa fa-exclamation-triangle","label":"Warning"}},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"content/ch01/modification.md","mtime":"2020-03-24T11:10:36.704Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-03-24T13:21:20.286Z"},"basePath":"../..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../../gitbook/gitbook.js"></script>
    <script src="../../gitbook/theme.js"></script>
    
        
        <script src="../../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-flexible-alerts/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-auto-scroll-table/plugin.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../../gitbook/gitbook-plugin-theme-comscore/test.js"></script>
        
    

    </body>
</html>

